{include file="public/_meta"}
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start" value="{$search.start}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end" value="{$search.end}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="title"  placeholder="请输入商品名称" autocomplete="off" class="layui-input" value="{$search.title}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>

                                <div class="layui-inline layui-show-xs-block">
                                    <a class="layui-btn" href="add"><i class="layui-icon"></i>发布新商品</a>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                      <th width="30">id</th>
                                      <th width="30">排序</th>
                                      <th>商品名称</th>
                                      <th class="text-center" width="30">商品图片</th>
                                      <th class="text-center" width="30">库存</th>
                                      <th class="text-center" width="150">发布时间</th>
                                      <th class="text-center" width="30">状 态</th>
                                      <th class="text-center" width="30">是否推荐</th>
                                      <th>操作管理</th>
                                  </tr>
                                </thead>
                                <tbody>
                                {volist name="data" id="v"}
                                  <tr>
                                    <td>{$v.id}</td>
                                      <td><input type="text" class="layui-input x-sort changeSort" data-id="{$v.id}" name="list_order" value="{$v.list_order}"></td>
                                      <td title="{$v.title}">{$v.title_cut}</td>
                                    <td><img src="{$v.recommend_image}" alt="" height="100"></td>
                                    <td>{$v.stock}</td>
                                    <td>{$v.create_time}</td>
                                    <td  class="td-status">
                                        {if condition="$v.status == 1"}
                                      <span onclick="changeStatus(0, {$v['id']})" class="layui-btn layui-btn-normal layui-btn-mini">已发布</span>
                                        {else\}
                                        <span onclick="changeStatus(1, {$v['id']})" class="layui-btn layui-btn-danger layui-btn-mini">未发布</span>
                                        {/if}
                                    </td>

                                      <td data-id="{$v.id}">
                                          <input type="checkbox" {if $v.is_index_recommend == 1}checked{/if} name="status" lay-skin="switch"
                                          lay-filter="switchStatus"
                                          lay-text="ON|OFF">
                                      </td>
                                    <td class="td-manage">
                                        <a class="layui-btn"  onclick="xadmin.open('商品详情','detail',600,400)" href="javascript:;">
                                            详情
                                        </a>
                                      <a class="layui-btn"  onclick="xadmin.open('编辑','edit',600,400)" href="javascript:;">
                                          编辑
                                      </a>
                                      <a  class="layui-btn"  onclick="goods_del(this,{$v['id']})" href="javascript:;">
                                        删除
                                      </a>
                                    </td>
                                  </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                {$data->render()|raw}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>

        //排序
        $('.changeSort').on('change',function () {
            let id = $(this).attr('data-id');
            let val = $(this).val();
            if(!val){
                return;
            }
            let url = '{:url("goods/listorder")}?id=' + id + '&listorder='+val;
            $.get(url,function (res) {
                if(res.status == 0) {
                    window.location.reload();
                } else {
                    layer.msg("排序失败");
                }
            })

        })

        function changeStatus(status,id ) {
            let url = '{:url("goods/status")}?id=' + id + '&status='+status;
            $.get(url,function (res) {
                if(res.status == 0) {
                    window.location.reload();
                } else {
                    layer.msg("操作失败");
                }
            })
        }
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });

          form.on('switch(switchStatus)', function (obj) {

              let id = obj.othis.parent().attr('data-id');
              let status = obj.elem.checked ? 1 : 0;
              $.ajax({
                  url: '{:url("goods/recommendStatus")}?id=' + id + '&status=' + status,
                  success: (res) => {
                      if(res.status == 0) {
                          window.location.reload();
                      } else {
                          layer.msg("操作失败");
                      }
                  }
              });
              return false;
          });


      });



      /*用户-删除*/
      function goods_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              let url = '{:url("goods/delete")}?id=' + id ;
              $.get(url, function (res) {
                  if (res.status == 0) {
                      $(obj).parents("tr").remove();
                      layer.msg('已删除!',{icon:1,time:1000});
                  } else  {
                      layer.msg('操作失败!',function () {
                          
                      });
                      return false
                  }
              }, 'json')

          });
      }



      function delAll (argument) {
        var ids = [];

        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要删除吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>
</html>